"""
Copyright (C) 2008 Masahiro Nakao

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""

import functions
    
class Parameter:
    # Set Default parameters if no ARGV
    def __init__(self, argv):
        self.seed = 0
        self.number_of_layers = 8
        self.number_of_each_individuals = 8
        self.number_of_dimensions = 2
        self.amp = 2.0
        # min_range = 0.0000001 # nearly 0.0, not <= 0
        self.min_range = 0.00001
        # Rastrigin, Ridge-1.0, Schwefel, Griewank-1.0, Rastrigin-1.0, Rosenbrock
        self.function = "Rastrigin-1.0"
        
        num = len(argv)
        if num > 1:
            if argv[1] == "-h":
                print "Argument\t\t\tDefault Value"
                print "--seed\t\t\t\t" + str(self.seed)
                print "--number_of_layers\t\t" + str(self.number_of_layers)
                print "--number_of_each_individuals\t" + str(self.number_of_each_individuals)
                print "--number_of_dimensions\t\t" + str(self.number_of_dimensions)
                print "--min_range\t\t\t" + str(self.min_range)
                print "--amp\t\t\t\t" + str(self.amp)
                print "--function \t\t\t" + str(self.function)
                print " function ->",
                print "Rastrigin, Ridge, Schwefel, Rosenbrock, Griewank, Rastrigin-1.0, Ridge-1.0, Griewank-1.0"   
                exit (0)
            else:
                i = 1
                while(num > i):
                    if argv[i] == "--seed":
                        self.seed = int(argv[i+1])
                    elif argv[i] == "--number_of_layers":
                        self.number_of_layers = int(argv[i+1])
                    elif argv[i] == "--number_of_each_individuals":
                        self.number_of_each_individuals = int(argv[i+1])
                    elif argv[i] == "--number_of_dimensions":
                        self.number_of_dimensions = int(argv[i+1])
                    elif argv[i] == "--amp":
                        self.amp = float(argv[i+1])
                    elif argv[i] == "--function":
                        self.function = argv[i+1]
                    elif argv[i] == "--min_range":
                        self.min_range = float(argv[i+1])
                    else:
                        print "Error!! Unknown Parameter \"" + argv[i] + "\""
                        exit (1)
                    i += 2
        
        # Static Parameters
        self.min_value = functions.get_range(self.function)[0]
        self.max_value = functions.get_range(self.function)[1]
        self.max_range = float(self.max_value) / 2
        self.max_number_of_generations = 10000
        self.max_number_of_evaluations = 3e+8
        self.minimum_value = 1e-8
    
    def get_seed(self):
        return self.seed
    
    def get_number_of_layers(self):
        return self.number_of_layers
    
    def set_number_of_layers(self, value):
        self.number_of_layers = value
    
    def get_number_of_each_individuals(self):
        return self.number_of_each_individuals
    
    def set_number_of_each_individuals(self, value):
        self.number_of_each_individuals = value
    
    def get_number_of_dimensions(self):
        return self.number_of_dimensions
    
    def set_amp(self, value):
        self.amp = value
    
    def get_amp(self):
        return self.amp
    
    def set_number_of_dimensions(self, value):
        self.number_of_dimensions = value
        
    def get_max_range(self):
        return self.max_range
    
    def set_max_range(self, value):
        self.max_range = value
        
    def get_min_range(self):
        return self.min_range
    
    def set_min_range(self, value):
        self.min_range = value
        
    def get_max_value(self):
        return self.max_value
        
    def get_min_value(self):
        return self.min_value
        
    def get_function(self):
        return self.function
        
    def get_max_number_of_generations(self):
        return self.max_number_of_generations
            
    def get_minimum_value(self):
        return self.minimum_value
        
    def get_max_number_of_evaluations(self):
        return self.max_number_of_evaluations
        
    def show_parameter(self):
        print "Function:\t\t\t" + self.function
        print "Seed:\t\t\t\t" + str(self.seed)
        print "Number of Layers:\t\t" + str(self.number_of_layers)
        print "Number of each individuals:\t" + str(self.number_of_each_individuals)
        print "Number of dimensions:\t\t" + str(self.number_of_dimensions)
        print "Amp:\t\t\t\t" + str(self.amp)
        print "Upper bound:\t\t\t" + str(self.max_value)
        print "Lower bound:\t\t\t" + str(self.min_value)
        print "Max Range:\t\t\t" + str(self.max_range)
        print "Min Range:\t\t\t" + str(self.min_range)
        
if __name__ == '__main__':
    argv = ["hoge", "--seed", "4", "--function","Griewank", "--min_range","0.01"]
    argv += ["--number_of_layers","10", "--number_of_each_individuals", "111"]
    argv += ["--number_of_dimensions", "12"]
    pm = Parameter(argv)
    pm.show_parameter()
    print "-------------------------------------------"
    print pm.get_seed()
    print pm.get_function()
    print pm.get_min_range()
    print pm.get_number_of_layers()
    print pm.get_number_of_each_individuals()
    print pm.get_number_of_dimensions()
    print pm.get_max_range()
    print pm.get_max_value()
    print pm.get_min_value()
    print pm.get_max_number_of_generations()
    print pm.get_minimum_value()
    print pm.get_max_number_of_evaluations()
